$env:path += ";C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\"
$env:path += ";C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\"
$env:path += ";C:\Windows\Microsoft.NET\Framework\v4.0.30319"
$env:path += ";C:\Windows\Microsoft.NET\Framework\v3.5"
$env:path += ";C:\Program Files\Vim\vim72"
$env:path += ";C:\svn"
$env:path += ";C:\msysgit\bin"
$env:path += ";C:\cygwin\bin"
$env:path += ";C:\ruby\bin"
$env:path += ";C:\emacs\emacs-23.1\bin"
$env:path += ";C:\Program Files\Reflector"
$env:path += ";C:\cygwin\bin"
$env:path += ";" + (($env:windir) + "\system32\inetsrv")

function global:hello {
  write-host $(get-content env:computername) -fore yellow	
}

function global:devenv {
  $args | %{ devenv.exe (Resolve-Path $_) }
}	

function global:touch {
  set-content -Path ($args[0]) -Value ([String]::Empty) 
}

function global:editor {
  $args | %{ e.exe (Resolve-Path $_) }
}

function global:sqlreset {
  NET STOP MSSQLSERVER
  NET START MSSQLSERVER
}

function global:kill-process([string] $process_name){
  Get-Process | Where { $_.Name -Eq $process_name } | Kill
  $msg =  "{0} was killed" -f $process_name
  write-host $msg -fore yellow 
}

function global:iiskill {
  kill-process w3wp
}

function global:vi {
  $args | %{ vim.exe (Resolve-Path $_) } 
}

function global:emacs {
  runemacs.exe -fs -Q
}

function global:setup-shell {
  (Get-Host).UI.RawUI.BufferSize = (Get-Host).UI.RawUI.MaxPhysicalWindowSize
  (Get-Host).UI.RawUI.WindowSize = (Get-Host).UI.RawUI.MaxPhysicalWindowSize
#  (Get-Host).UI.RawUI.WindowTitle = 'Command'
  $host.ui.rawui.windowtitle = $(get-location)
  write-host ($(get-date).tostring("dd HH:mm:ss") + ">") -nonewline - foregroundcolor gray
  return " "
}

function global:grep {
  get-childitem -include ($args[0]) -recurse | select-string -pattern ($args[1])
}

function global:cassini {
  webdev.webserver.exe $args
}

function global:cassinikill {
  kill-process WebDev.WebServer
}

function global:hosts {
  editor \Windows\System32\drivers\etc\hosts
}

function global:install-file([string] $urlPath) {
  $filename = download-file($urlPath)
  invoke-item $filename
}

function global:download-file([string] $urlPath) {
  $urlSplit = $urlPath.split('/')
  $filename = (Resolve-Path .\).ToString() + '\' + $urlSplit[$urlSplit.length - 1]
  $webclient = New-Object "System.Net.WebClient"
  $webclient.DownloadFile($urlPath, $filename)
  return $filename
}

function global:install-ruby {
  install-file http://rubyforge.org/frs/download.php/47082/ruby186-27_rc2.exe
}

function global:install-git {
  install-file http://msysgit.googlecode.com/files/Git-1.6.4-preview20090730.exe
}

function global:install-cygwin {
  install-file http://www.cygwin.com/setup.exe
}

function global:install-svn {
  install-file http://downloads-guests.open.collab.net/files/documents/61/1635/CollabNetSubversion-client-1.5.6-2.win32.exe
}

function global:install-emacs {
  install-file http://ftp.gnu.org/gnu/emacs/windows/emacs-23.1-bin-i386.zip
}

function global:install-e {
  install-file http://www.e-texteditor.com/download/e_setup.exe
}

function global:curl([string] $urlPath) {
  $webclient = New-Object "System.Net.WebClient"
  return $webclient.DownloadString($urlPath)
}

function global:delete-hidden-svn-directories(){
  ls -fo -re | where {$_.mode -match "d"} | where {$_.name -match ".svn"} | rm -fo
}

function global:delete-debug-directories(){
  ls -fo -re | where {$_.mode -match "d"} | where {$_.name -match "debug"} | rm -fo -re
}


function global:reflector(){
  $args | %{ Reflector.exe (Resolve-Path $_) }
}

function global:tfs-checkout([string] $filename){
  tf checkout $filename
  e $filename
}

function global:gcc(){
  gcc-3.exe $args
}

function global:tfs-get{
  tf get .\ /recursive
}

function global:tfs-merge([string] $filename1, [string] $filename2){
  tf merge /baseless (Resolve-Path $filename1) (Resolve-Path $filename1) /recursive
}

function global:config-debug-off{
  $configFile = (Resolve-Path  web.config)
    
  $webConfig = [xml](Get-Content $configFile)
  
  $webConfig.SelectSingleNode('//system.web/customErrors').RemoveAll()
  $webConfig.SelectSingleNode('//system.webServer/httpErrors').RemoveAll()

  $webConfig.Save($configFile)
}

#Cygwin compiler aliases
function global:gcc{
  gcc-3.exe $args
}

function global:cc{
  gcc
}

function global:c++{
  gcc
}

function global:get-assembly-name([string] $assemblyName){
  $assembly = ([System.Reflection.Assembly]::Loadfile( (resolve-path $assemblyName) ))
  write-host $assembly.GetName()
  $assembly = $null
}


function global:list-w3wp{
  write-host $(appcmd list wp) -Separator `n -fore green
}
function global:list-wp{
  list-w3wp
}

#ideas:
# remove custom errors from web.config files